import { flat, uniqueJsonArray } from '@/util/index'

//extra
import extra from './lang.extra'
//baseData
import bank from './baseData/bank/index'
import bankAccount from './baseData/bankAccount'
import bankAccountType from './baseData/bankAccountType'
import client from './baseData/client/index'
import creditLevel from './baseData/creditLevel/index'
import language from './baseData/language/index'
import paymentTerm from './baseData/paymentTerm/index'
import country from './baseData/country/index'
import currency from './baseData/currency/index'
import rate from './baseData/rate/index'
import paymentMethod from './baseData/paymentMethod'
import logistics from './baseData/logistics/index'
// receipt
import receipt from './receipt/index'
// guarantee
import guarantee from './guarantee/index'
//ARInvoice
import arInvoice from './ARInvoice/index'
//writeOff
import writeOff from './writeOff/index'
//dataReserve
import dataReserve from './dataReserve/index'

const dataModule = {
  extra,
  baseData: { bank, bankAccount, bankAccountType, client, creditLevel, language, paymentTerm, country, currency, rate, paymentMethod, logistics },
  receipt,
  guarantee,
  arInvoice,
  writeOff,
  dataReserve
}

function dataModuleToJsonArray(obj) {
  const ret = []
  const transform = function(obj) {
    Object.keys(obj).forEach(key => {
      if (Array.isArray(obj[key])) {
        ret.push(...obj[key])
      } else {
        transform(obj[key])
      }
    })
  }
  transform(obj)
  return ret
}

export default uniqueJsonArray(dataModuleToJsonArray(dataModule))
